home *** CD-ROM | disk | FTP | other *** search
- Program MouseText;
-
- (* *)
- (* An Example Program for TheMouse *)
- (* A Turbo Pascal Mouse Unit by Kevin Kwast *)
- (* *)
-
- Uses Crt, Dos, TMouse5; {Change to TMouse4 if using Turbo Pascal 4}
-
- Var
- tmInit: TheMouseInitType; {These types are in TheMouse}
- tmEvent: TheMouseEventType;
-
- Done, DrawAgain: Boolean;
-
- OrigTextCursor: Word;
-
- (*** Here is the event handler.. ***)
-
- {$F+} { Far Calls for Event Handler }
-
- Procedure Event(Flags, CS, AX, BX, CX, DX, SI, DI, DS, ES, BP: Word);
-
- {This will be called by the mouse driver, and must have this format}
- Interrupt;
-
- Begin
- tmEvent.EventMask := AX;
- tmEvent.ButtonStatus := BX;
- tmEvent.Column := CX;
- tmEvent.Row := DX;
-
- Inline ( { exit for far return to mouse device driver }
- $8B/$E5/ { Mov SP,BP }
- $5D/ { Pop BP }
- $07/ { Pop ES }
- $1F/ { Pop DS }
- $5F/ { Pop DI }
- $5E/ { Pop SI }
- $5A/ { Pop DX }
- $59/ { Pop CX }
- $5B/ { Pop BX }
- $58/ { Pop AX }
- $CB ); { RETF }
- End;
-
- {$F-}
-
- Procedure SaveTextCursor;
- Var Regs: Registers;
- Begin
- Regs.AH:=3;
- Intr($10, Regs);
- OrigTextCursor:=Regs.CX;
- End;
-
- Procedure OffTextCursor;
- Var Regs: Registers;
- Begin
- Regs.AH:=1;
- Regs.CX:=$0D0D;
- Intr($10, Regs);
- End;
-
- Procedure RestoreTextCursor;
- Var Regs: Registers;
- Begin
- Regs.AH:=1;
- Regs.CX:=OrigTextCursor;
- Intr($10, Regs);
- End;
-
- Function TextX(MousX: Word) : Byte;
- Begin
- TextX:=(MousX div 8) + 1;
- End;
-
- Function TextY(MousY: Word) : Byte;
- Begin
- TextY:=(MousY div 8) + 1;
- End;
-
- Procedure DoDemo;
- Begin
- DrawAgain:=True; {Tells Main to redraw after running this}
- tmCursor(False);
- ClrScr; {See what happens when you don't do this}
- tmCursor(True);
- TextColor(7);
- GotoXY(31,25);
- Write('Click Right to Exit');
- GotoXY(18,2);
- Write('TheMouse makes it easy to handle the mouse!');
- GotoXY(15,3);
- Write('Click the left button to put a star on the screen.');
-
- tmRowRange(25,190); {Don't let mouse onto text}
-
- TextColor(12); {Star will be light red}
-
- Repeat
- tmEvent.EventMask:=0;
- REPEAT UNTIL tmEvent.EventMask <> 0;
-
- If (tmEvent.EventMask and $4 <> 0) then
- Begin
- GotoXY(TextX(tmEvent.Column), TextY(tmEvent.Row));
- tmCursor(False);
- Write('*'); {Again, this is necessary}
- tmCursor(True);
- End; { If left button released, put a star.. }
-
- Until (tmEvent.EventMask and $10 <> 0); {Stop when right released}
-
- tmRowRange(0,199);
- End;
-
- Procedure DoInfo;
- Begin
- DrawAgain:=True; {Tells Main to redraw after running this}
- tmCursor(False);
- ClrScr;
- tmCursor(True);
- GotoXY(5,3);
- Write('TheMouse provides routines for text and graphics both.');
- GotoXY(5,5);
- Write('The perfect routines for your Turbo Pascal toolbox!');
- GotoXY(21,20);
- Write('> Click Right Here to Go Back to Main <');
- REPEAT {Sit in Loop}
- UNTIL ((tmEvent.EventMask and $10 <> 0)
- and (TextY(tmEvent.Row) = 20)
- and (TextX(tmEvent.Column) in [21..59]));
- End;
-
- Procedure DoHelp;
- Begin
- DrawAgain:=True; {Tells Main to redraw after running this}
- tmCursor(False);
- ClrScr;
- tmCursor(True);
- GotoXY(5,8);
- Write('Move onto an option the same way you chose this to go to that section.');
- GotoXY(15,10);
- Write('Now click left in the box to exit --> [ ]');
- REPEAT {Sit in Loop}
- UNTIL (tmEvent.EventMask and $4 <> 0) and (TextX(tmEvent.Column) = 62);
- End;
-
- Procedure DoQuit;
- Var X: Byte;
- Begin
- DrawAgain:=True; {Tells Main to redraw after running this}
- tmCursor(False);
- ClrScr;
- tmCursor(True);
- GotoXY(27,25);
- Write('Click Right on your Choice');
- GotoXY(26,4);
- Write('Do you want to quit?');
- GotoXY(48,4);
- TextColor(14);
- Write('YES NO');
-
- REPEAT
- X:=TextX(tmEvent.Column);
- UNTIL (tmEvent.EventMask and $10 <> 0) and (X in [48..50,53,54]);
-
- If X in [48..50] then Done:=True;
- End;
-
- (* This program is very rough, and is just meant to *)
- (* give you an idea how to use TheMouse in text mode. *)
-
- Begin
- tmReset(tmInit);
- If NOT tmInit.Exists then Begin
- WriteLn('Mouse driver not found.');
- Halt;
- End;
-
- SaveTextCursor;
- OffTextCursor;
-
- tmTextCursor(0, 0, $0EFE); {Sets cursor to Character FE, Attribute E}
- tmTask($17, seg(Event), ofs(Event)); {Trap Left & Right Button Releases}
- { Also left button press }
-
- Done:=False;
-
- Repeat
-
- tmCursor(False);
- ClrScr;
- TextColor(14);
- GotoXY(18,1);
- Write('Demo Info Help Quit');
- TextColor(7);
- GotoXY(24,25);
- Write('Click Left Button on your Choice');
-
- tmCursor(True);
-
- DrawAgain:=False;
- Repeat
- tmEvent.EventMask:=0;
- REPEAT UNTIL tmEvent.EventMask <> 0;
- CASE tmEvent.EventMask of
- $04, {Left Button or Left with Motion}
- $05: If TextY(tmEvent.Row) = 1 then
- Case TextX(tmEvent.Column) of
- 17..22: DoDemo;
- 30..35: DoInfo;
- 43..48: DoHelp;
- 56..61: DoQuit;
- End;
- END;
- Until DrawAgain;
-
- Until Done;
-
- tmReset(tmInit); { Re-initialize mouse.. Must do this! }
- { Otherwise, the task will cause the computer to hang! }
-
- RestoreTextCursor;
- ClrScr;
- End.